home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / probots.arc / ASSASSIN.PR < prev    next >
Text File  |  1991-04-28  |  3KB  |  98 lines

  1.   PROCEDURE Assassin;
  2.     { Based on a C-Robot by John R. Naleszkiewicz }
  3.  
  4.     { Scanning routine calls itself recursively with successively }
  5.     { smaller scan widths until the opponent is destroyed or lost. }
  6.     { This robot is always moving to a new random point. }
  7.  
  8.     { "Global" variables, can be used by any function or procedure }
  9.  
  10.   VAR
  11.     x, y           : Integer; { traveling toward this location }
  12.     travelCount    : Integer; { change direction every so often }
  13.     Angle          : Integer; { angle of travel for the robot  }
  14.     hitAngle, hitRange : Integer; { used to pin-point opponent     }
  15.     Switch         : Boolean; { scanning increment TRUE = minus, FALSE = plus }
  16.  
  17.     { make sure the robot is moving in the right direction }
  18.     PROCEDURE evade;
  19.     BEGIN
  20.       travelCount := travelCount-1;
  21.       IF ((travelCount = 0) OR (speed < 51)) THEN
  22.         BEGIN
  23.           drive(Angle, 0); {Slow Down}
  24.           x := Random(800)+100;
  25.           y := Random(800)+100;
  26.           Angle := Angle_To(x, y);
  27.           travelCount := 4;
  28.           WHILE (speed > 49) DO {Nothing} ;
  29.           drive(Angle, 100);
  30.         END;
  31.     END; { end of evade }
  32.  
  33.     FUNCTION NextHitAngle(increment : Integer) : Integer;
  34.     BEGIN
  35.       IF Switch THEN
  36.         NextHitAngle := hitAngle+increment
  37.       ELSE
  38.         NextHitAngle := hitAngle-increment;
  39.     END; { end of nextHitAngle }
  40.  
  41.  
  42.     { scan and fire with increaseing resolution until target is lost }
  43.     PROCEDURE find_n_fire(width, missCount : Integer);
  44.       { width: integer ;          scan width }
  45.       { missCount: integer ;      how many scans before reversing direction }
  46.     VAR
  47.       width2         : Integer;
  48.     BEGIN
  49.       IF (width < 2) THEN
  50.         BEGIN
  51.           width := 2;
  52.           evade;
  53.         END;
  54.  
  55.       width2 := width*2;
  56.  
  57.       IF Switch THEN
  58.         hitAngle := hitAngle-width2*2
  59.       ELSE
  60.         hitAngle := hitAngle+width2*2;
  61.  
  62.       hitRange := scan(NextHitAngle(width2), width);
  63.       missCount := missCount-1;
  64.       WHILE ((hitRange = 0) OR (hitRange > 700)) AND (missCount <> 0) DO
  65.         BEGIN
  66.           hitRange := scan(NextHitAngle(width2), width);
  67.           missCount := missCount-1;
  68.         END;
  69.  
  70.       IF hitRange <> 0 THEN
  71.         BEGIN
  72.           cannon(hitAngle, hitRange);
  73.           find_n_fire((width DIV 2), 10);
  74.         END
  75.       ELSE
  76.         BEGIN
  77.           IF (scan(NextHitAngle(13), 10) = 0) THEN
  78.             BEGIN
  79.               Switch := NOT Switch;
  80.               IF Switch
  81.               THEN hitAngle := hitAngle+13
  82.               ELSE hitAngle := hitAngle-13;
  83.             END;
  84.           evade;
  85.         END;
  86.     END; { end of find_n_fire }
  87.  
  88.   BEGIN {Assassin Main}
  89.     hitAngle := 0; { scanning angle }
  90.     Switch := True; { scanning increment direction }
  91.     travelCount := 0; { intialize travel count }
  92.     evade; { make sure movment is in the right direction }
  93.     REPEAT { loop is executed "forever" }
  94.       find_n_fire(8, 23); { find the opponent and shoot }
  95.     UNTIL Dead OR Winner;
  96.   END; { end of Assassin Main }
  97.  
  98.